#include <cairo.h>  
#include <gtk/gtk.h>  
   
cairo_surface_t *image;  
   
static gboolean  
on_expose_event(GtkWidget *widget,  
    GdkEventExpose *event,  
    gpointer data)  
{  
  cairo_t *cr;  
   
  cr = gdk_cairo_create (widget->window);  
   
  cairo_set_source_surface(cr, image, 0, 0);  
  cairo_paint(cr);  
   
  cairo_destroy(cr);  
   
  return FALSE;  
}  
   
   
int main(int argc, char *argv[])  
{  
  GtkWidget *window;  
  gint width, height; 
  /* 用一幅 png 图片来创建一份图像外观。出于效率的考虑，应在主函数中调用这个函数。 
   * 这里窗口根据图片大小进行显示
   */
  image = cairo_image_surface_create_from_png("../assert/back.png");  
  width = cairo_image_surface_get_width (image);
  height = cairo_image_surface_get_height (image);
  gtk_init(&argc, &argv);  
   
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);  
   
  g_signal_connect(window,"expose-event",  
      G_CALLBACK (on_expose_event), NULL);  
  g_signal_connect(window,"destroy",  
      G_CALLBACK (gtk_main_quit), NULL);  
   
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);  
  gtk_window_set_default_size(GTK_WINDOW(window), width, height);  
  gtk_widget_set_app_paintable(window, TRUE);  
   
  gtk_widget_show_all(window);  
   
  gtk_main();  
   
  cairo_surface_destroy(image);  
   
  return 0;  
}  
